package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.MainPostBean;
import com.project.mapper.IMainPostMapper;
import com.project.mapper.IReturnPostMapper;
import com.project.service.IMainPostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

@Service
@Transactional
public class MainPostServiceImpl implements IMainPostService {

    @Autowired
    private IMainPostMapper mapper;
    @Autowired
    private IReturnPostMapper returnMapper;
    private static final int PAGESIZE=2;
    @Override
    public PageInfo<MainPostBean> findByItem(int pageNo,int channelId, String theme, String author, LocalDate startDate, LocalDate endDate) {
        PageHelper.startPage(pageNo,PAGESIZE);
        PageInfo<MainPostBean> info = PageInfo.of(mapper.findByItem(channelId, theme, author, startDate, endDate));
        return info;
    }

    @Override
    public void add(MainPostBean mainPostBean) {
        mapper.add(mainPostBean);
    }

    @Override
    public MainPostBean findById(int id) {
        MainPostBean main = new MainPostBean();
        main.setReturnList(returnMapper.findByMainPost(id));
        return main;
    }
}
